#include "discovery/eventfd_types.h"
#include <cstring>
#include <chrono>
#include <unistd.h>

TransferMessage::TransferMessage() {
    memset(this, 0, sizeof(*this));
    sender_pid = getpid();
    timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
        std::chrono::system_clock::now().time_since_epoch()).count();
    message_id = 0;
    priority = 0;
    flags = 0;
}

void TransferMessage::set_message_type(const std::string& type) {
    strncpy(message_type, type.c_str(), sizeof(message_type) - 1);
    message_type[sizeof(message_type) - 1] = '\0';
}

void TransferMessage::set_topic_name(const std::string& topic) {
    strncpy(topic_name, topic.c_str(), sizeof(topic_name) - 1);
    topic_name[sizeof(topic_name) - 1] = '\0';
}

void TransferMessage::set_custom_data(const std::string& data) {
    strncpy(custom_data, data.c_str(), sizeof(custom_data) - 1);
    custom_data[sizeof(custom_data) - 1] = '\0';
}

std::string TransferMessage::get_message_type() const {
    return std::string(message_type);
}

std::string TransferMessage::get_topic_name() const {
    return std::string(topic_name);
}

std::string TransferMessage::get_custom_data() const {
    return std::string(custom_data);
}
